home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-15 | 3.1 KB | 55 lines | [TEXT/MPS ] |
- Validation of entry into Modal Dialogs
-
- I apologize for the fragmentary nature of this submission, but it is culled from some
- Fortran code I happened to have with me, and as I do not have the Language Systems
- Fortran compiler with me, and rewriting it in C was not something I had time to
- do, it is submitted as is. There are some INCLUDE files I do not have with me, but
- if there is serious interest in this hack, I will try to grind out a working demo
- later. I cannot submit the entire program in which this feature exists, as there
- is code in it which I did not write.
-
- The problem which this hack (and it is a hack, in every sense of the word) addresses
- is how to solicit free text input from users and provide validation during entry.
- The conditions this example covers are integers in a range, floating point in a range
- (including the scientific format), and charater strings within a range of number of
- characters. Also doable (but not done here) would be money, time, dates, etc.
-
- The approach is to attempt to reject an invalid key press when possible, i.e. if
- the addition of that character to the string makes the string no longer meet the
- SANE definition for representation of a floating point, don't add it to the string.
- If the character is a valid character, but causes the string to exceed the bounds of
- the specified format, add it to the string, but draw the string as greyed text and
- grey the default round rect so the user understands that the value needs to be fixed
- before proceeding. The user can see the validation criteria by pressing the option key.
-
- In order to do this, we need several components:
-
- 1) NumValFilter, a ModalDialog filter proc which handles keyboard and mouse events
- 2) ctlDimItem, a userItem which handles greying the text within the specified
- dialog item
- 3) A Frm# resource, which specifies the validation criteria and the item in which
- to display the validation criteria. Note that due to the inability of Rez
- to generate a floating point number in a civilized fashion, I build this resource
- with the assembler. How embarrising for Apple...
- 4) A routine which sets up the ModalDialog call
-
- As in any hack, there are areas in which this code battles nobly against the
- operating system (and wins). Specifically, if the user selects several characters
- and then presses a key, we need to carefully evaluate what the result will be,
- lest we replace a valid number with a letter. Also, we need to clean up the field
- if there was a selection range and the user tabs or clicks out of the field, as
- the Dialog manager will try to redraw the field and ungrey the text.
-
- Since I wrote all this, I believe I know better ways to do what I am doing, and
- may well rewrite this in C++, but I submit it mainly as an experiment in the human
- interface which addresses a problem many of us face every day - how to avoid pissing
- off the user by beeping and putting up an alert after the fact.
-
- Jeff E Mandel MD MS
- Asst Professor of Anesthesiology
- 1430 Tulane Ave
- Tulane University School of Medicine
- New Orleans, LA 70112
-
- (504) 588 5903
- AS01MEF@VM.TCS.TULANE.EDU